﻿using MyX.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LearningEnglish.Models
{
    public class LearnUserService
    {
        static LearnUserService()
        {
            LearnUsers = new List<Tuple<Guid, string, string>>();
        }

        public static void Add(Guid id, string name, string password)
        {
            if (LearnUsers.Exists(x => x.Item1 == id) || LearnUsers.Exists(x => x.Item2 == name))
                throw new Exception("已存在该学习者");

            LearnUsers.Add(new Tuple<Guid, string, string>(id, name, password));
        }

        public static bool HasForName(string name)
        {
            return LearnUsers.Exists(x => x.Item2 == name);
        }

        public static bool Has(string name,string password)
        {
            return LearnUsers.Exists(x => x.Item2 == name && x.Item3 == password);
        }

        public static Guid Find(string name,string password)
        {
            var last = LearnUsers.Find(x => x.Item2 == name && x.Item3 == password);
            if (last == null)
                throw new Exception("未找到该用户");
            return last.Item1;
        }

        public static List<Tuple<Guid, string, string>> LearnUsers { get; set; }
    }
}